﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JinJun.YShowReception.BLL.IService;
using JinJun.YShowReception.DAL.IRepository;
using JinJun.YShowReception.DAL.Repository;
using JinJun.YShowReception.Model;
using JinJun.YShowReception.Remoto;

namespace JinJun.YShowReception.BLL.Service
{
    public class SmsInfoService:ISmsInfoService
    {
        private ISmsInfoRepository _smsInfoRepository;
        public SmsInfoService(ISmsInfoRepository smsInfoRepository)
        {
            _smsInfoRepository = smsInfoRepository;
        }


        /// <summary>
        /// 添加短信发送记录
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public bool AddSmsInfo(string tel)
        {
            //创建腾讯云对象
            TenXunYunSMS tenXunYunSMS = new TenXunYunSMS();
            try
            {
                //获取配置信息
                tenXunYunSMS.appId = Convert.ToInt32(ConfigurationManager.AppSettings["appId"]);
                tenXunYunSMS.appKey = ConfigurationManager.AppSettings["appKey"];
                tenXunYunSMS.SetSMS(tel);
            }
            catch (Exception ex)
            {
                return false;
            }
            //创建短信类对象
            SmsInfo smsInfo = new SmsInfo();
            //赋值
            smsInfo.Code = tenXunYunSMS.Code;
            smsInfo.TelPhone = Convert.ToInt64(tel);
            //调用添加短信发送记录
            return _smsInfoRepository.AddSmsInfo(smsInfo) > 0;
        }


        /// <summary>
        /// 查询验证码是否存在
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public int CheckCode(SmsInfo smsInfo)
        {
            //调用查询验证码是否存在
            return _smsInfoRepository.CheckCode(smsInfo);
        }

    }
}
